package cn.hlyc.mq.transaction;

import org.apache.rocketmq.client.producer.LocalTransactionState;
import org.apache.rocketmq.client.producer.TransactionListener;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.common.message.MessageExt;

public class MyTransactionListener implements TransactionListener {

    /**
     * 执行本地事务
     * @param message
     * @param o
     * @return
     */
    @Override
    public LocalTransactionState executeLocalTransaction(Message message, Object o) {

        excuteTransaction();

        System.out.println(o);

        //成功用COMMIT_MESSAGE  失败用ROLLBACK_MESSAGE
        return LocalTransactionState.COMMIT_MESSAGE;

    }

    @Override
    public LocalTransactionState checkLocalTransaction(MessageExt messageExt) {
        return null;
    }

    private void excuteTransaction(){
        System.out.println("执行本地事务");
    }
}
















